#!/usr/bin/python
# -*- coding: utf-8 -*-
import gtk
import gobject
import sys
import os
import socket
import gettext
from DownloadView import DownloadView
from ConfigView import ConfigView
import time

_ = gettext.gettext
        
class Menu(gobject.GObject):
    __gsignals__ = {
        'state-changed': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_INT,gobject.TYPE_INT)),
    }
    def __init__(self):
        gobject.GObject.__init__(self)
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.box = gtk.VBox(homogeneous=False, spacing=0)
        self.window.add(self.box)
        self.window.set_destroy_with_parent(True)
        self.window.set_icon_from_file('icon2.png')
        self.window.connect("destroy", self.windowDestroy)
        self.window.connect("delete_event", self.dummyDelete)
        
        
        table = gtk.Table(3, 6, False)
        self.box.pack_start(table)
        notebook = gtk.Notebook()
        notebook.set_tab_pos(gtk.POS_TOP)
        table.attach(notebook, 0, 6, 0, 1)
        notebook.show()
        
        label = gtk.Label(_('Download'))
        downloadView = DownloadView()
        notebook.append_page(downloadView, label)
        
        label2 = gtk.Label(_('Config'))
        configView = ConfigView(downloadView.setConfig)
        notebook.append_page(configView, label2)
        
        self.window.set_title('RDMMenu')
        self.window.set_focus_on_map(1)
        self.window.set_app_paintable(1)
        #self.window.set_skip_taskbar_hint(1)
        #self.window.set_skip_pager_hint(1)
        self.window.set_opacity(1)
        self.window.set_decorated(1)
        #self.window.set_keep_above(0) #Make this always above other windows
        self.window.stick() #Make this appear on all desktops
        self.window.set_default_size(500,400)
        self.window.set_events(gtk.gdk.ALL_EVENTS_MASK)
        self.window.set_position(gtk.WIN_POS_CENTER)
        self.x, self.y = self.window.get_position()
        self.view = False
        self.showHideMenu()
        
    def windowDestroy(self, widget, data=None):
        gtk.main_quit()
        return True
        
    def dummyDelete(self, widget, data=None):
        self.hide()
        return True
        
    def show(self):
        self.window.move(self.x, self.y)
        self.window.show_all()
        self.view = True
        return True

    def hide(self):
        self.x, self.y = self.window.get_position()
        self.view = False
        self.window.hide()
    
    def showHideMenu(self):
        if self.view == False:
            self.show()
        else:
            self.hide()
            
